<?php
/**
 * Created by PhpStorm.
 * User: Yueool
 * Date: 2020/3/3
 * Time: 16:33
 */

namespace collecter\data\tasks;

class Jb implements \collecter\components\PageTask {

    public function test(){
        echo "testclass";
    }

    public function getTasks($page){

        $url = "http://www.5uwl.net/wyjs/mirjs/mirsfjb/list_5_".$page.".html";

        $content = file_get_contents($url);

        $content = iconv("gbk","utf-8//IGNORE",$content)  ;

        $content = preg_replace("/[\n\r]/", "", $content);//去换行
        $content = preg_replace("/\s+/", " ", $content);//去换行
        //echo $content;

        preg_match("/<div\sclass=\"lie\">(.*?)<\/div><\/div><\/div><\/div><\/div><\/div>/", $content, $matches);
        //print_r($matches);

        $main = isset($matches[1]) ? $matches[1] : "";

        preg_match_all('/<div\sclass=\"lie_18\"><a\shref=\"([^<>]+?)\">(.*?)<\/a>/', $main, $matches);
        $data = [];
        foreach($matches[1] as $key => $value){
            $data[$key]["url"] = "http://www.5uwl.net".$value;
        }
        foreach($matches[2] as $key => $value){
            $data[$key]["name"] = $value;
        }
        //echo '<pre>';print_r($data);

        return $data;
    }

}